package com.summer.common.lib.core.listeners;

import com.summer.common.lib.config.WebConfig;
import com.summer.common.lib.context.WebContext;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.logging.Logger;

@WebListener
public class ServletContextDIInitializer implements ServletContextListener {

    static Logger logger = Logger.getLogger(ServletContextDIInitializer.class.getName());

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        new WebConfig(sce.getServletContext());
        // 组件注册与注入
        new WebContext(sce.getServletContext());
        logger.info("所有的 JNDI 组件名称：[");
        WebContext.getInstantiate().getAllComponentNames().forEach(logger::info);
        logger.info("]");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}
